package cn.wolfcode.luowowo.search.query;

import cn.wolfcode.luowowo.common.query.QueryObject;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

@Getter
@Setter
public class SearchQueryObject extends QueryObject {
    //地区类型
    public static final int CONDITION_TYPE_ABROAD = 0;  //国外
    public static final int CONDITION_TYPE_UN_ABROAD = 1;  //国内
    public static final int CONDITION_TYPE_THEME = 2;  //主题

    //搜索条件的类型
    public static final int SEARCH_TYPE_ALL = -1;       //所有
    public static final int SEARCH_TYPE_DEST = 0;       //目的地
    public static final int SEARCH_TYPE_STRATEGY = 1;   //攻略
    public static final int SEARCH_TYPE_TRAVEL = 2;     //游记
    public static final int SEARCH_TYPE_USER = 3;       //用户


    private int type = -1;  //条件类别: 国内,国外,主题
    private Long typeValue = -1L;   //国内(provinceId)  国外(countryId)    主题(themeid)

    private String orderBy = "viewNum"; //排序对象阅读数

    /**
     * 分页排序规则
     * @return
     * 参数1:当前页(要-1)
     * 参数2:每页显示的条数
     * 参数3:排序规则,排序的对象
     */
    public Pageable getPageable(){
        return PageRequest.of(super.getCurrentPage()-1 , super.getPageSize(), Sort.by(Sort.Direction.DESC,orderBy));
    }

    public Pageable getPageableNoSort(){
        return PageRequest.of(super.getCurrentPage()-1 , super.getPageSize());
    }
}
